/**
 * 
 */
package net.dfrz.java1305.team4.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author acer
 * 
 */
public class DBUtils {

	private static final DBUtils DB_UTILS = new DBUtils();

	private DBUtils() {

	}

	/**
	 * 获取DBUtils实例
	 * 
	 * @return DBUtils实例
	 */
	public static DBUtils getInstance() {
		return DB_UTILS;
	}

	/**
	 * JDBC连接
	 * 
	 * @return 连接
	 */
	public Connection getConnection() {
		Connection conn = null;

		try {
			Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");

			conn = DriverManager.getConnection("proxool.onlineShoppingSys-ds");

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return conn;
	}

	/**
	 * 释放资源
	 * 
	 * @param connection 连接资源
	 *        
	 * @param statement 准备资源
	 *            
	 * @param resultSet 结果集资源
	 *            
	 */
	public void release(Connection connection, Statement statement,
			ResultSet resultSet) {
		try {
			if (resultSet != null) {
				resultSet.close();
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (statement != null) {
					statement.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				try {
					if (connection != null) {
						connection.close();
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
